package com.ruoyi.web.controller.wx;


import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.mapper.ByParamMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/wx/param")
@Validated
public class WxParamController {
    @Autowired
    private ByParamMapper paramMapper;

    @PostMapping("getParamByPid")
    public AjaxResult getParamByPid(@RequestBody String param){
        JSONObject json = JSONObject.parseObject(param);
        String pid = json.getString("pid");
        if(StringUtils.isEmpty(pid)){
            return AjaxResult.success();
        }
        List<JSONObject> list = paramMapper.getParamByPid(pid);
        return AjaxResult.success(list);
    }


    @PostMapping("getParamByid")
    public AjaxResult getParamByid(@RequestBody String param){
        JSONObject json = JSONObject.parseObject(param);
        String id = json.getString("id");
        if(StringUtils.isEmpty(id)){
            return AjaxResult.success();
        }
        JSONObject entity = paramMapper.getParamJSONObjectById(id);
        return AjaxResult.success(entity);
    }
}
